package com.atguigu.tingshu.album.config;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/***
 * 搜索微服务同步专辑微服务
 */
@Configuration
public class AlbumAndSearchRabbitConfig {

    //定义一个交换机
    @Bean
    public Exchange AlbumAndSearchexchange(){
        return ExchangeBuilder.directExchange("Album_Search_exchange").build();
    }
    //定义上架队列
    @Bean
    public Queue AlbumAndSearchUpperQueue (){
        return QueueBuilder.durable("AlbumA_Search_upper_queue").build();
    }

    //定义下架队列
    @Bean
    public Queue AlbumAndSearchDownQueue (){
        return QueueBuilder.durable("AlbumA_Search_Down_queue").build();
    }

    //定义Redis队列
    @Bean
    public Queue albumAndSearchQueueRedis (){return QueueBuilder.durable("album_Search_Queue_Redis").build();}

    //绑定Redis队列
    @Bean
    public Binding albumAndSearchBindRedis (@Qualifier(value = "albumAndSearchQueueRedis") Queue albumAndSearchQueueRedis,
                                            @Qualifier(value = "AlbumAndSearchexchange")Exchange AlbumAndSearchexchange){
        return BindingBuilder.bind(albumAndSearchQueueRedis).to(AlbumAndSearchexchange).with("album-redis").noargs();
    }

    //绑定上架队列
    @Bean
    public Binding AlbumAndSearchBindUpperQueue (@Qualifier(value = "AlbumAndSearchUpperQueue") Queue AlbumAndSearchUpperQueue,
    @Qualifier(value = "AlbumAndSearchexchange")Exchange AlbumAndSearchexchange ){
        return BindingBuilder.bind(AlbumAndSearchUpperQueue).to(AlbumAndSearchexchange).with("album-upper").noargs();
    }

    //绑定下架队列
    @Bean
    public Binding AlbumAndSearchBindDownQueue (@Qualifier(value = "AlbumAndSearchDownQueue") Queue AlbumAndSearchDownQueue,
                                                 @Qualifier(value = "AlbumAndSearchexchange")Exchange AlbumAndSearchexchange ){
        return BindingBuilder.bind(AlbumAndSearchDownQueue).to(AlbumAndSearchexchange).with("album-down").noargs();
    }
}
